package com.yizhu.zczy.system.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.yizhu.zczy.common.utils.PageUtils;
import com.yizhu.zczy.common.utils.R;
import com.yizhu.zczy.system.vo.PermissionsVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yizhu.zczy.system.entity.RoleRightsEntity;
import com.yizhu.zczy.system.service.RoleRightsService;




/**
 * 角色对应权限表
 *
 * @author guoyz
 * @email guoyz@mail.com
 * @date 2021-06-24 18:31:46
 */
@RestController
@RequestMapping("system/rolerights")
public class RoleRightsController {
    @Autowired
    private RoleRightsService roleRightsService;



    @GetMapping("/getPermissionsByRoleId")
    @ApiOperation(value = "根据角色查询权限信息")
    public R getPermissionsByRole(@RequestParam Integer roleId){
        List<PermissionsVo> permissionsVos = roleRightsService.GetPermissionsByRole(roleId);
        return R.ok().setData(permissionsVos);
    }

    @PostMapping("/modifyPermissionsByRoleId")
    @ApiOperation("根据角色id修改权限的信息")
    public R modifyPermissionsByRoleId(@RequestParam("roleId") Integer roleId,@RequestParam("popedomIds") List<Integer> popedomIds){
       roleRightsService.modifyPermissionsByRoleId(roleId,popedomIds);
       return R.ok();
    }



    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("system:rolerights:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = roleRightsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{roleRightId}")
    //@RequiresPermissions("system:rolerights:info")
    public R info(@PathVariable("roleRightId") Integer roleRightId){
		RoleRightsEntity roleRights = roleRightsService.getById(roleRightId);

        return R.ok().put("roleRights", roleRights);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("system:rolerights:save")
    public R save(@RequestBody RoleRightsEntity roleRights){
		roleRightsService.save(roleRights);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("system:rolerights:update")
    public R update(@RequestBody RoleRightsEntity roleRights){
		roleRightsService.updateById(roleRights);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("system:rolerights:delete")
    public R delete(@RequestBody Integer[] roleRightIds){
		roleRightsService.removeByIds(Arrays.asList(roleRightIds));

        return R.ok();
    }

}
